package com.sw.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sw.dao.UserDao;
import com.sw.model.User;
import com.sw.service.UserService;
@Service
public class UserServiceImpl implements UserService{

	@Autowired
	private UserDao userDao;
	
	@Override
	public boolean login(User user) {
		User currentUser = userDao.getUser(user);
		if(currentUser != null){
			return true;
		}
		
		return false;
	}

	@Override
	public boolean register(User user){
		User currentUser = userDao.findUserByPhone(user.getPhone());
		if(currentUser != null){
			return false;
		}
		int i = userDao.insertUser(user);
		if(i != 1){
			return false;
		}
		return true;
	}

	@Override
	public boolean changePassword(User user) {
		User currentUser = userDao.getUserById(user.getId());
		if(currentUser != null){
			int i = userDao.updateUser(user);
			if(i != 1){
				return false;
			}
		}
		return true;
	}

}
